//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_base.h"
#include "h_xml.h"
#include "h_global.h"
using namespace h_base;
using namespace h_xml;

#include "h_g.h"
#include "h_portal.h"
#include "h_server.h"

#include "t_confirmform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TConfirmForm *ConfirmForm;
//---------------------------------------------------------------------------
__fastcall TConfirmForm::TConfirmForm(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool __fastcall TConfirmForm::DoConfirm(HBatchIcon *Batch,
   const UTF8String &Title, const UTF8String &Auth)
{
   OkFlag = false;
   Label1->Caption = Title;

   if ( !h_g::RememberPasswordFlag )
   {
      EditPassword->Text = "";
   }

   ShowModal();

   if ( !OkFlag )
   {
      return false;
   }

   UTF8String Id = EditId->Text.TrimRight();
   UTF8String Password = EditPassword->Text.TrimRight();
   UTF8String ErrStr;

   if ( !HServer::FuncLogin(Batch, Id, Password, Auth, ErrStr) )
   {
      return false;
   }

   Batch->Lock();
   Batch->LastLoginId = Id;
   Batch->Unlock();
   return true;
}

bool __fastcall TConfirmForm::Confirm(HBatchIcon *Batch,
   const UTF8String &Title, const UTF8String &Auth)
{
   LabelBatchDate->Visible = false;
   EditBatchDate->Visible = false;
   LabelNextBatchDate->Visible = false;
   EditNextBatchDate->Visible = false;
   LabelEndBatchDate->Visible = false;
   EditEndBatchDate->Visible = false;
   return DoConfirm(Batch, Title, Auth);
}

bool __fastcall TConfirmForm::ConfirmRestartJob(HBatchIcon *Batch,
   UTF8String &BatchDate, UTF8String &NextBatchDate,
   const UTF8String &Title, const UTF8String &Auth)
{
   LabelBatchDate->Visible = BatchDate != "";
   LabelBatchDate->Enabled = true;
   EditBatchDate->Visible = BatchDate != "";
   EditBatchDate->ReadOnly = false;
   LabelNextBatchDate->Visible = BatchDate != "";
   EditNextBatchDate->Visible = BatchDate != "";
   EditNextBatchDate->ReadOnly = false;
   LabelEndBatchDate->Visible = false;
   EditEndBatchDate->Visible = false;
   EditBatchDate->Text = BatchDate;
   EditNextBatchDate->Text = "";

   if ( !DoConfirm(Batch, Title, Auth) )
   {
      return false;
   }

   BatchDate = EditBatchDate->Text.TrimRight();
   NextBatchDate = EditNextBatchDate->Text.TrimRight();
   return true;
}

bool __fastcall TConfirmForm::ConfirmStartBatch(HBatchIcon *Batch,
   const UTF8String &BatchDate,
   const UTF8String &Title, const UTF8String &Auth)
{
   LabelBatchDate->Visible = BatchDate != "";
   LabelBatchDate->Enabled = false;
   EditBatchDate->Visible = BatchDate != "";
   EditBatchDate->ReadOnly = true;
   LabelNextBatchDate->Visible = false;
   EditNextBatchDate->Visible = false;
   LabelEndBatchDate->Visible = false;
   EditEndBatchDate->Visible = false;
   EditBatchDate->Text = BatchDate;

   return DoConfirm(Batch, Title, Auth);
}

bool __fastcall TConfirmForm::ConfirmStartBatch(HBatchIcon *Batch,
   UTF8String &BatchDate, UTF8String &NextBatchDate, UTF8String &EndBatchDate,
   const UTF8String &Title, const UTF8String &Auth)
{
   LabelBatchDate->Visible = true;
   LabelBatchDate->Enabled = true;
   EditBatchDate->Visible = true;
   EditBatchDate->ReadOnly = false;
   LabelNextBatchDate->Visible = true;
   EditNextBatchDate->Visible = true;
   LabelEndBatchDate->Visible = true;
   EditEndBatchDate->Visible = true;
   EditBatchDate->Text = BatchDate;
   EditNextBatchDate->Text = "";
   EditEndBatchDate->Text = "";

   if ( !DoConfirm(Batch, Title, Auth) )
   {
      return false;
   }

   BatchDate = EditBatchDate->Text.TrimRight();
   NextBatchDate = EditNextBatchDate->Text.TrimRight();
   EndBatchDate = EditEndBatchDate->Text.TrimRight();
   return true;
}

void __fastcall TConfirmForm::ButtonOkClick(TObject *Sender)
{
   OkFlag = true;
   Close();
}
//---------------------------------------------------------------------------
void __fastcall TConfirmForm::ButtonCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------
void __fastcall TConfirmForm::FormShow(TObject *Sender)
{
   if ( EditId->Text == "" )
   {
      EditId->SetFocus();
   }
   else
   {
      EditPassword->SetFocus();
   }
}
//---------------------------------------------------------------------------

